<?php

namespace Application\BankAccount\Test\Entity;

use Application\BankAccountBundle\Entity\BankAccount;

class BankAccountTest extends \PHPUnit_Framework_TestCase
{
    public function testBalanceInitialization()
    {
        $account = new BankAccount();
        $this->assertEquals($account->getBalance(), 0);
        
        $account = new BankAccount(1000);
        $this->assertEquals($account->getBalance(), 1000);
    }

    public function testCreditAccount()
    {
        $account = new BankAccount();
        $account->credit(500);
        $this->assertEquals($account->getBalance(), 500);
        
        $account->credit(1000);
        $this->assertEquals($account->getBalance(), 1500);
    }

    public function testDebitAccount()
    {
        $account = new BankAccount();
        $account->debit(800.50);
        $this->assertEquals($account->getBalance(), -800.50);
        
        $account = new BankAccount(1000);
        $account->debit(200);
        $this->assertEquals($account->getBalance(), 800);
    }

    public function testTransfer()
    {
        $accountA = new BankAccount(1200);
        $accountB = new BankAccount(185);
        
        $accountA->transfer(200, $accountB);
        
        $this->assertEquals($accountA->getBalance(), 1000);
        $this->assertEquals($accountB->getBalance(), 385);
    }
}